//创建一个大文件.读取出最多的字符
let fs=require("fs");
// if(!fs.existsSync("biggest")) fs.mkdirSync("biggest");//假设biggest文件不在则创建biggest文件
if(!fs.existsSync("biggest")){
    fs.mkdirSync("biggest");
}
let str="qeewtasetdr4wwegsdfgsfb";
let startAt= new Date() .getTime();// 开始的时间
let fd=fs.openSync("./biggest/big.txt","a");
for (let i = 0; i < 1000000; i++) {
    fs.writeSync(fd,str.slice(Math.floor(Math.random()*(str.length-1))),str.length-1);   
}
fs.closeSync(fd);
let endAt=new Date().getTime();
// console.log(endAt - startAt);

//读取最多字符
let chatArray =[]; 
let readSteam = fs.createReadStream("./biggest/big.txt");
readSteam.on("data",(chunk)=>{
    let str =chunk.toString();
    // console.log(str);
    for(let i=0;i<str.length;i++){
        if(chatArray[str[i]]==undefined){
            chatArray[str[i]]=1;
        }else{
            chatArray[str[i]]+=1;
        }
    }

});

readSteam.on("end",()=>{
    console.log(chatArray);
})
// var max =0;
// var str2='';


